package com.sujeet.activity.tracker.web.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sujeet.activity.tracker.model.access.ActivityCrudUtils;
import com.sujeet.activity.tracker.web.ParameterValueUtils;

/**
 * Servlet implementation class AddActivity
 */
public class AddActivity extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public AddActivity() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		double estimatedEffort = ParameterValueUtils.getEstimatedEffort(
				request.getParameter(ParameterValueUtils.ESTIMATED_EFFORT),
				8.0D);
		Date startDate = ParameterValueUtils.getDate(
				request.getParameter(ParameterValueUtils.START_DATE),
				new Date());
		String changeLog = ParameterValueUtils.getChangeLog(request
				.getParameter(ParameterValueUtils.CHANGE_LOG));
		
		ActivityCrudUtils acu = new ActivityCrudUtils();	
		acu.createOneActivity(estimatedEffort, startDate, changeLog);
		
//		PrintWriter out = response.getWriter();
//		out.println("Estimated effort: " + estimatedEffort);
//		out.println("Start date: " + startDate.toString());
//		out.println("Change log: " + changeLog);
		
		System.out.println("Adding.. ");
		System.out.println("Estimated effort: " + estimatedEffort);
		System.out.println("Start date: " + startDate.toString());
		System.out.println("Change log: " + changeLog);
		
		response.sendRedirect("/com.sujeet.activity.tracker.web/Show");
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
